//
//  YKCheckCell.m
//  ZBarScan
//
//  Created by QFYK on 2017/5/24.
//  Copyright © 2017年 QF_iOS. All rights reserved.
//

#import "YKCheckCell.h"

@implementation YKCheckCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self config];
    }
    return self;
}

- (void)config
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.backgroundColor = [UIColor clearColor];
    _infoLb = [UILabel createLabelFrame:CGRectMake(10, 0, 100, 44) title:nil titleColor:YKColor16Hex(0x333333) titleFont:16 bgColor:nil radius:0 inSuperView:self isSizeToFit:NO];
    _contentLb = [UILabel createLabelFrame:CGRectMake(CGRectGetMaxX(_infoLb.frame) + 10, 0, kScreenW - CGRectGetMaxX(_infoLb.frame) - 20, 44) title:nil titleColor:YKCOLOR_MAIN titleFont:16 bgColor:[UIColor clearColor] radius:0 inSuperView:self isSizeToFit:NO];
    
    UIBezierPath *lineBePath = [UIBezierPath bezierPath];
    [lineBePath moveToPoint:CGPointMake(0,  44 - 0.5)];
    [lineBePath addLineToPoint:CGPointMake(kScreenWidth, 44 - 0.5)];
    
    CAShapeLayer *shaperLayer = [[CAShapeLayer alloc] init];
    shaperLayer.strokeColor = [YKColor16Hex(0x666666) CGColor];
    
    shaperLayer.lineWidth = 0.5f;
    shaperLayer.path = lineBePath.CGPath;
    [self.layer addSublayer:shaperLayer];
}

- (void)transmitData:(YKProductInfo *)ykData andUserType:(NSInteger)userType andIndexPath:(NSIndexPath *)indexPath
{
    switch (userType) {
        case 0:
            [self GZtransmitData:ykData andIndexPath:indexPath];
            break;
        case 1:
            [self JXStransmitData:ykData andIndexPath:indexPath];
            break;
            
        default:
            [self GCtransmitData:ykData andIndexPath:indexPath];
            break;
    }
}

- (void)GZtransmitData:(YKProductInfo *)ykData andIndexPath:(NSIndexPath *)indexPath
{
    if (ykData == nil) {
        _infoLb.text = @"您扫描的码有误，请返回重新扫描!";
        [UILabel isSizeToFit:_infoLb andWidth:kScreenW - 20];
        _infoLb.frame = CGRectMake(_infoLb.frame.origin.x, 0, _infoLb.frame.size.width, self.frame.size.height);
        return;
    }
    if (indexPath.section == 0) {_infoLb.text = [NSString stringWithFormat:@"商品名称："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProductName];}
    else if (indexPath.section == 1) {_infoLb.text = [NSString stringWithFormat:@"品牌："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.Brand];}
    else if (indexPath.section == 2) {_infoLb.text = [NSString stringWithFormat:@"规格："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProductSpec];}
    else if (indexPath.section == 3) {_infoLb.text = [NSString stringWithFormat:@"生产时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProduceTime];}
    else if (indexPath.section == 4) {_infoLb.text = [NSString stringWithFormat:@"生产工厂："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.FactoryName];}
    else if (indexPath.section == 5) {_infoLb.text = [NSString stringWithFormat:@"扫描次数："];
        _contentLb.text = [NSString stringWithFormat:@"%ld" , ykData.SCanNumber];}
    else if (indexPath.section == 6) {_infoLb.text = [NSString stringWithFormat:@"首次扫码时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ScanTime];}
    [UILabel isSizeToFit:_infoLb andWidth:kScreenW - 20];
    _infoLb.center = CGPointMake(_infoLb.center.x, self.frame.size.height / 2);
    _contentLb.frame = CGRectMake(CGRectGetMaxX(_infoLb.frame), 0, kScreenW - CGRectGetMaxX(_infoLb.frame) - 20, 44);
    [UILabel isSizeToFit:_contentLb andWidth:_contentLb.frame.size.width];
    _contentLb.center = CGPointMake(_contentLb.center.x, self.frame.size.height / 2);
}

- (void)GCtransmitData:(YKProductInfo *)ykData andIndexPath:(NSIndexPath *)indexPath
{
    if (ykData == nil) {
        _infoLb.text = @"您扫描的码有误，请返回重新扫描!";
        [UILabel isSizeToFit:_infoLb andWidth:kScreenW - 20];
        _infoLb.frame = CGRectMake(_infoLb.frame.origin.x, 0, _infoLb.frame.size.width, self.frame.size.height);
        return;
    }
    if (indexPath.section == 0) {_infoLb.text = [NSString stringWithFormat:@"商品名称："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProductName];}
    else if (indexPath.section == 1) {_infoLb.text = [NSString stringWithFormat:@"品牌："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.Brand];}
    else if (indexPath.section == 2) {_infoLb.text = [NSString stringWithFormat:@"规格："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProductSpec];}
    else if (indexPath.section == 3) {_infoLb.text = [NSString stringWithFormat:@"生产时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProduceTime];}
    else if (indexPath.section == 4) {_infoLb.text = [NSString stringWithFormat:@"生产工厂："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.FactoryName];}
    else if (indexPath.section == 5) {_infoLb.text = [NSString stringWithFormat:@"销售区域："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.SaleRegion];}
    else if (indexPath.section == 6) {_infoLb.text = [NSString stringWithFormat:@"订单编号："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.OrderNumber];}
    else if (indexPath.section == 7) {_infoLb.text = [NSString stringWithFormat:@"装车单号："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.PLCode];}
    else if (indexPath.section == 8) {_infoLb.text = [NSString stringWithFormat:@"装车数量："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.Number];}
    else if (indexPath.section == 9) {_infoLb.text = [NSString stringWithFormat:@"装车时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.PackingTime];}
    else if (indexPath.section == 10) {_infoLb.text = [NSString stringWithFormat:@"到货地点："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ArriveAt];}
    else if (indexPath.section == 11) {_infoLb.text = [NSString stringWithFormat:@"扫描次数："];
        _contentLb.text = [NSString stringWithFormat:@"%ld" , ykData.SCanNumber];}
    else if (indexPath.section == 12) {_infoLb.text = [NSString stringWithFormat:@"首次扫码时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ScanTime];}
    [UILabel isSizeToFit:_infoLb andWidth:kScreenW - 20];
    _infoLb.center = CGPointMake(_infoLb.center.x, self.frame.size.height / 2);
    _contentLb.frame = CGRectMake(CGRectGetMaxX(_infoLb.frame), 0, kScreenW - CGRectGetMaxX(_infoLb.frame) - 20, 44);
    [UILabel isSizeToFit:_contentLb andWidth:_contentLb.frame.size.width];
    _contentLb.center = CGPointMake(_contentLb.center.x, self.frame.size.height / 2);
}

- (void)JXStransmitData:(YKProductInfo *)ykData andIndexPath:(NSIndexPath *)indexPath
{
    if (ykData == nil) {
        _infoLb.text = @"您扫描的码有误，请返回重新扫描!";
        [UILabel isSizeToFit:_infoLb andWidth:kScreenW - 20];
        _infoLb.frame = CGRectMake(_infoLb.frame.origin.x, 0, _infoLb.frame.size.width, self.frame.size.height);
        return;
    }
    if (indexPath.section == 0) {_infoLb.text = [NSString stringWithFormat:@"商品名称："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProductName];}
    else if (indexPath.section == 1) {_infoLb.text = [NSString stringWithFormat:@"品牌："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.Brand];}
    else if (indexPath.section == 2) {_infoLb.text = [NSString stringWithFormat:@"规格："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProductSpec];}
    else if (indexPath.section == 3) {_infoLb.text = [NSString stringWithFormat:@"生产时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ProduceTime];}
    else if (indexPath.section == 4) {_infoLb.text = [NSString stringWithFormat:@"生产工厂："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.FactoryName];}
    else if (indexPath.section == 5) {_infoLb.text = [NSString stringWithFormat:@"销售区域："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.SaleRegion];}
    else if (indexPath.section == 6) {_infoLb.text = [NSString stringWithFormat:@"订单编号："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.OrderNumber];}
    else if (indexPath.section == 7) {_infoLb.text = [NSString stringWithFormat:@"经销商名称："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.DealerName];}
    else if (indexPath.section == 8) {_infoLb.text = [NSString stringWithFormat:@"联系电话："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.DealerNumber];}
    else if (indexPath.section == 9) {_infoLb.text = [NSString stringWithFormat:@"装车单号："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.PLCode];}
    else if (indexPath.section == 10) {_infoLb.text = [NSString stringWithFormat:@"装车数量："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.Number];}
    else if (indexPath.section == 11) {_infoLb.text = [NSString stringWithFormat:@"车牌号码："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.NumberPlate];}
    else if (indexPath.section == 12) {_infoLb.text = [NSString stringWithFormat:@"司机姓名："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.DriverName];}
    else if (indexPath.section == 13) {_infoLb.text = [NSString stringWithFormat:@"司机电话："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.DriverNumber];}
    else if (indexPath.section == 14) {_infoLb.text = [NSString stringWithFormat:@"装车时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.PackingTime];}
    else if (indexPath.section == 15) {_infoLb.text = [NSString stringWithFormat:@"到货地点："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ArriveAt];}
    else if (indexPath.section == 16) {_infoLb.text = [NSString stringWithFormat:@"接收人："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.Receiver];}
    else if (indexPath.section == 17) {_infoLb.text = [NSString stringWithFormat:@"接收人电话："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ReceiverNumber];}
    else if (indexPath.section == 18) {_infoLb.text = [NSString stringWithFormat:@"接收人地址："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ReceiverPlace];}
    else if (indexPath.section == 19) {_infoLb.text = [NSString stringWithFormat:@"扫描次数："];
        _contentLb.text = [NSString stringWithFormat:@"%ld" , ykData.SCanNumber];}
    else if (indexPath.section == 20) {_infoLb.text = [NSString stringWithFormat:@"首次扫码时间："];
        _contentLb.text = [NSString stringWithFormat:@"%@" , ykData.ScanTime];}
    
    [UILabel isSizeToFit:_infoLb andWidth:kScreenW - 20];
    _infoLb.center = CGPointMake(_infoLb.center.x, self.frame.size.height / 2);
    _contentLb.frame = CGRectMake(CGRectGetMaxX(_infoLb.frame), 0, kScreenW - CGRectGetMaxX(_infoLb.frame) - 20, 44);
    [UILabel isSizeToFit:_contentLb andWidth:_contentLb.frame.size.width];
    _contentLb.center = CGPointMake(_contentLb.center.x, self.frame.size.height / 2);
}

-(void)backCellHeight:(void(^)(CGFloat height))cellHeight
{
    CGFloat h = _contentLb.frame.size.height;
    if (h > 44) {
        cellHeight(h);
        return;
    }
    cellHeight(44);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
